local xiangcan = fk.CreateSkill{
  name = "lingling__xiangcan",
}

Fk:loadTranslationTable{
  ["lingling__xiangcan"] = "相残",
  [":lingling__xiangcan"] = "结束阶段，你可以令所有角色依次将一张牌当冰【杀】或火【杀】使用（不能使用则跳过），若你因此造成伤害，你失去1点体力。",

  ["#lingling__xiangcan-invoke"] = "相残：是否令所有角色依次将一张牌当冰【杀】或火【杀】使用？",
  ["#lingling__xiangcan-use"] = "相残：请将一张牌当冰【杀】或火【杀】使用",
}

xiangcan:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xiangcan.name) and player.phase == Player.Finish
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = xiangcan.name,
      prompt = "#lingling__xiangcan-invoke",
    }) then
      event:setCostData(self, {tos = room:getAlivePlayers()})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, to in ipairs(room:getAlivePlayers()) do
      if not to.dead then
        local use = room:askToUseVirtualCard(to, {
          name = {"ice__slash", "fire__slash"},
          skill_name = xiangcan.name,
          prompt = "#lingling__xiangcan-use",
          cancelable = false,
          extra_data = {
            bypass_times = true,
            extraUse = true,
          },
          card_filter = {
            n = 1,
          },
        })
        if use and to == player and use.damageDealt and not player.dead then
          room:loseHp(to, 1, xiangcan.name)
        end
      end
    end
  end,
})

return xiangcan
